﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for AccessData
/// </summary>
public class AccessData
{
    private static string ConnectString = ConfigurationManager.ConnectionStrings["connectDHAA"].ConnectionString;
    public SqlConnection GetConnect()
    {
        return new SqlConnection(ConnectString);
    }
    public DataTable GetTable(string sql)
    {
        SqlConnection conn = GetConnect();
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        SqlDataAdapter adap = new SqlDataAdapter(sql,conn);
        DataTable dt = new DataTable();
        adap.Fill(dt);
        conn.Close();
        return dt;
    }
    public void ExeCuteQuery(string sql)
    {
        SqlConnection conn = GetConnect();
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
    }
    public SqlDataReader ExecuteReader(string sql)
    {
        SqlConnection conn = GetConnect();
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataReader dr = cmd.ExecuteReader();
        return dr;
    }
}
